home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pbuild6 / frmproce.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-01-29  |  53.7 KB  |  1,340 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmProcedureBuilder 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Procedure Builder"
  6.    ClientHeight    =   4830
  7.    ClientLeft      =   1215
  8.    ClientTop       =   1905
  9.    ClientWidth     =   9960
  10.    BeginProperty Font 
  11.       Name            =   "Tahoma"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "frmProcedureBuilder.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   4830
  24.    ScaleWidth      =   9960
  25.    ShowInTaskbar   =   0   'False
  26.    Begin VB.CheckBox chkStatic 
  27.       Caption         =   "All local variables as statics"
  28.       Height          =   375
  29.       Left            =   240
  30.       TabIndex        =   35
  31.       Top             =   3600
  32.       Width           =   2295
  33.    End
  34.    Begin MSComctlLib.ListView lvParameters 
  35.       Height          =   1935
  36.       Left            =   3120
  37.       TabIndex        =   33
  38.       Top             =   840
  39.       Width           =   5895
  40.       _ExtentX        =   10398
  41.       _ExtentY        =   3413
  42.       View            =   3
  43.       LabelEdit       =   1
  44.       LabelWrap       =   -1  'True
  45.       HideSelection   =   -1  'True
  46.       FullRowSelect   =   -1  'True
  47.       _Version        =   393217
  48.       ForeColor       =   -2147483640
  49.       BackColor       =   -2147483643
  50.       BorderStyle     =   1
  51.       Appearance      =   1
  52.       NumItems        =   4
  53.       BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  54.          Text            =   "Parameters"
  55.          Object.Width           =   2540
  56.       EndProperty
  57.       BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  58.          SubItemIndex    =   1
  59.          Text            =   "Types"
  60.          Object.Width           =   2540
  61.       EndProperty
  62.       BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  63.          SubItemIndex    =   2
  64.          Text            =   "Passed By"
  65.          Object.Width           =   2540
  66.       EndProperty
  67.       BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  68.          SubItemIndex    =   3
  69.          Text            =   "Optional"
  70.          Object.Width           =   2540
  71.       EndProperty
  72.    End
  73.    Begin VB.CheckBox chkErrorOnly 
  74.       Caption         =   "Error Handling Only?"
  75.       Height          =   255
  76.       Left            =   240
  77.       TabIndex        =   32
  78.       Top             =   4380
  79.       Width           =   2175
  80.    End
  81.    Begin VB.CheckBox chkCommentOnly 
  82.       Caption         =   "Comment Template Only ?"
  83.       Height          =   255
  84.       Left            =   3120
  85.       TabIndex        =   31
  86.       Top             =   4380
  87.       Width           =   2175
  88.    End
  89.    Begin VB.TextBox txtOrganisation 
  90.       Height          =   360
  91.       Left            =   2580
  92.       TabIndex        =   1
  93.       TabStop         =   0   'False
  94.       Top             =   360
  95.       Width           =   3495
  96.    End
  97.    Begin VB.TextBox txtAuthor 
  98.       Height          =   345
  99.       Left            =   240
  100.       TabIndex        =   0
  101.       TabStop         =   0   'False
  102.       Top             =   360
  103.       Width           =   2190
  104.    End
  105.    Begin VB.CommandButton cmdDeleteParams 
  106.       Height          =   555
  107.       Left            =   9240
  108.       Picture         =   "frmProcedureBuilder.frx":0442
  109.       Style           =   1  'Graphical
  110.       TabIndex        =   28
  111.       Top             =   1560
  112.       Width           =   555
  113.    End
  114.    Begin VB.CheckBox chkOptional 
  115.       Caption         =   "Optional"
  116.       Height          =   420
  117.       Left            =   7950
  118.       TabIndex        =   13
  119.       Top             =   3030
  120.       Width           =   975
  121.    End
  122.    Begin VB.ComboBox cmbByRef 
  123.       Height          =   315
  124.       ItemData        =   "frmProcedureBuilder.frx":074C
  125.       Left            =   6975
  126.       List            =   "frmProcedureBuilder.frx":0756
  127.       TabIndex        =   12
  128.       Top             =   3150
  129.       Width           =   915
  130.    End
  131.    Begin VB.ComboBox cmbParameterType 
  132.       Height          =   315
  133.       ItemData        =   "frmProcedureBuilder.frx":0768
  134.       Left            =   5610
  135.       List            =   "frmProcedureBuilder.frx":0793
  136.       Sorted          =   -1  'True
  137.       TabIndex        =   11
  138.       Top             =   3150
  139.       Width           =   1365
  140.    End
  141.    Begin VB.CommandButton cmdAdd 
  142.       Height          =   555
  143.       Left            =   9240
  144.       Picture         =   "frmProcedureBuilder.frx":07FD
  145.       Style           =   1  'Graphical
  146.       TabIndex        =   14
  147.       ToolTipText     =   "Add Parameters"
  148.       Top             =   2175
  149.       Width           =   540
  150.    End
  151.    Begin VB.TextBox txtParameterName 
  152.       Height          =   315
  153.       Left            =   4065
  154.       TabIndex        =   10
  155.       Top             =   3150
  156.       Width           =   1530
  157.    End
  158.    Begin VB.ComboBox cmbReturnType 
  159.       Height          =   315
  160.       ItemData        =   "frmProcedureBuilder.frx":0B07
  161.       Left            =   1200
  162.       List            =   "frmProcedureBuilder.frx":0B2C
  163.       Sorted          =   -1  'True
  164.       TabIndex        =   5
  165.       TabStop         =   0   'False
  166.       Top             =   2400
  167.       Visible         =   0   'False
  168.       Width           =   1695
  169.    End
  170.    Begin VB.CheckBox chkCommentTemplate 
  171.       Caption         =   "Add Comment Template ?"
  172.       Height          =   375
  173.       Left            =   3120
  174.       TabIndex        =   9
  175.       Top             =   3960
  176.       Value           =   1  'Checked
  177.       Width           =   2295
  178.    End
  179.    Begin VB.CheckBox chkErrorHandling 
  180.       Caption         =   "Add Error Handling ?"
  181.       Height          =   375
  182.       Left            =   240
  183.       TabIndex        =   8
  184.       Top             =   3960
  185.       Value           =   1  'Checked
  186.       Width           =   1815
  187.    End
  188.    Begin VB.Frame frmType 
  189.       Height          =   720
  190.       Left            =   240
  191.       TabIndex        =   19
  192.       Top             =   2820
  193.       Width           =   2640
  194.       Begin VB.OptionButton optFriend 
  195.          Caption         =   "Friend"
  196.          Height          =   255
  197.          Left            =   1680
  198.          TabIndex        =   34
  199.          Top             =   300
  200.          Width           =   810
  201.       End
  202.       Begin VB.OptionButton optPrivate 
  203.          Caption         =   "Private"
  204.          Height          =   375
  205.          Left            =   840
  206.          TabIndex        =   7
  207.          Top             =   240
  208.          Width           =   840
  209.       End
  210.       Begin VB.OptionButton optPublic 
  211.          Caption         =   "Public"
  212.          Height          =   375
  213.          Left            =   120
  214.          TabIndex        =   6
  215.          Top             =   240
  216.          Value           =   -1  'True
  217.          Width           =   735
  218.       End
  219.    End
  220.    Begin VB.TextBox txtName 
  221.       Height          =   345
  222.       Left            =   240
  223.       TabIndex        =   2
  224.       Top             =   1020
  225.       Width           =   2175
  226.    End
  227.    Begin VB.Frame frmProcedureBuilder 
  228.       Height          =   735
  229.       Left            =   255
  230.       TabIndex        =   17
  231.       Top             =   1440
  232.       Width           =   2640
  233.       Begin VB.OptionButton optFunction 
  234.          Caption         =   "Function"
  235.          Height          =   375
  236.          Left            =   1440
  237.          TabIndex        =   4
  238.          Top             =   240
  239.          Width           =   1080
  240.       End
  241.       Begin VB.OptionButton optProcedure 
  242.          Caption         =   "Procedure"
  243.          Height          =   255
  244.          Left            =   270
  245.          TabIndex        =   3
  246.          Top             =   315
  247.          Value           =   -1  'True
  248.          Width           =   1335
  249.       End
  250.    End
  251.    Begin VB.CommandButton CancelButton 
  252.       Caption         =   "Cancel"
  253.       Default         =   -1  'True
  254.       BeginProperty Font 
  255.          Name            =   "MS Sans Serif"
  256.          Size            =   8.25
  257.          Charset         =   0
  258.          Weight          =   400
  259.          Underline       =   0   'False
  260.          Italic          =   0   'False
  261.          Strikethrough   =   0   'False
  262.       EndProperty
  263.       Height          =   375
  264.       Left            =   8580
  265.       TabIndex        =   16
  266.       Top             =   4290
  267.       Width           =   1215
  268.    End
  269.    Begin VB.CommandButton OKButton 
  270.       Caption         =   "OK"
  271.       BeginProperty Font 
  272.          Name            =   "MS Sans Serif"
  273.          Size            =   8.25
  274.          Charset         =   0
  275.          Weight          =   400
  276.          Underline       =   0   'False
  277.          Italic          =   0   'False
  278.          Strikethrough   =   0   'False
  279.       EndProperty
  280.       Height          =   375
  281.       Left            =   8580
  282.       TabIndex        =   15
  283.       Top             =   3840
  284.       Width           =   1215
  285.    End
  286.    Begin VB.Label lblOrganisation 
  287.       Caption         =   "Organisation"
  288.       Height          =   315
  289.       Left            =   2640
  290.       TabIndex        =   30
  291.       Top             =   120
  292.       Width           =   1575
  293.    End
  294.    Begin VB.Label lblAuthor 
  295.       Caption         =   "Author"
  296.       Height          =   300
  297.       Left            =   240
  298.       TabIndex        =   29
  299.       Top             =   165
  300.       Width           =   705
  301.    End
  302.    Begin VB.Label lblOptional 
  303.       Caption         =   "Optional"
  304.       Height          =   255
  305.       Left            =   7860
  306.       TabIndex        =   27
  307.       Top             =   1290
  308.       Width           =   855
  309.    End
  310.    Begin VB.Label lblPassedBy 
  311.       Caption         =   "Passed By"
  312.       Height          =   300
  313.       Left            =   6945
  314.       TabIndex        =   26
  315.       Top             =   1275
  316.       Width           =   915
  317.    End
  318.    Begin VB.Label lblArgPassed 
  319.       Caption         =   "Passed By"
  320.       Height          =   270
  321.       Left            =   6960
  322.       TabIndex        =   25
  323.       Top             =   2925
  324.       Width           =   900
  325.    End
  326.    Begin VB.Label lblParameterTypes 
  327.       Caption         =   "Types"
  328.       Height          =   255
  329.       Left            =   5610
  330.       TabIndex        =   24
  331.       Top             =   1260
  332.       Width           =   855
  333.    End
  334.    Begin VB.Label lblParameterType 
  335.       Caption         =   "Parameter Type"
  336.       Height          =   255
  337.       Left            =   5595
  338.       TabIndex        =   23
  339.       Top             =   2940
  340.       Width           =   1245
  341.    End
  342.    Begin VB.Label lblParamNames 
  343.       Caption         =   "Parameter Name"
  344.       Height          =   255
  345.       Left            =   4080
  346.       TabIndex        =   22
  347.       Top             =   2940
  348.       Width           =   1695
  349.    End
  350.    Begin VB.Label lblParameters 
  351.       Caption         =   "Parameters"
  352.       Height          =   255
  353.       Left            =   4080
  354.       TabIndex        =   21
  355.       Top             =   1260
  356.       Width           =   1695
  357.    End
  358.    Begin VB.Label lblReturnType 
  359.       Caption         =   "Function Return Type"
  360.       Height          =   255
  361.       Left            =   1200
  362.       TabIndex        =   20
  363.       Top             =   2220
  364.       Visible         =   0   'False
  365.       Width           =   1695
  366.    End
  367.    Begin VB.Label lblName 
  368.       Caption         =   "Procedure/Function Name"
  369.       Height          =   240
  370.       Left            =   240
  371.       TabIndex        =   18
  372.       Top             =   780
  373.       Width           =   1860
  374.    End
  375. Attribute VB_Name = "frmProcedureBuilder"
  376. Attribute VB_GlobalNameSpace = False
  377. Attribute VB_Creatable = False
  378. Attribute VB_PredeclaredId = True
  379. Attribute VB_Exposed = False
  380. Public VBInstance As vbide.VBE
  381. Public Connect As Connect
  382. Option Explicit
  383. Private Sub chkErrorHandling_Click()
  384. ' Procedure chkErrorHandling_Click
  385. ' ----------------------------------------------------------------------
  386. ' Author        : Mark Kirkland
  387. ' Organisation  : Brighton Health Care
  388. ' Date          : 08/01/1999
  389. ' Description   :
  390. ' Amendments    :
  391. ' Error Handler
  392. On Error GoTo chkErrorHandling_Click_Error:
  393. ' Disable error handling only unless error handling is selected
  394. If Me.chkErrorHandling.Value = False Then
  395.     Me.chkErrorOnly.Enabled = False
  396.     Me.chkErrorOnly.Value = vbUnchecked
  397.     Me.chkErrorOnly.Enabled = True
  398. End If
  399. Exit Sub
  400. ' Error Routine
  401. chkErrorHandling_Click_Error:
  402. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In chkErrorHandling_Click"
  403. End Sub
  404. Private Sub chkCommentTemplate_Click()
  405. ' Procedure chkCommentTemplate_Click
  406. ' ----------------------------------------------------------------------
  407. ' Author        : Mark Kirkland
  408. ' Organisation  : Brighton Health Care
  409. ' Date          : 08/01/1999
  410. ' Description   :
  411. ' Amendments    :
  412. ' Error Handler
  413. On Error GoTo chkCommentTemplate_Click_Error:
  414. ' Disable comment only unless comment template is true
  415. If Me.chkCommentTemplate.Value = False Then
  416.     Me.chkCommentOnly.Enabled = False
  417.     Me.chkCommentOnly.Value = vbUnchecked
  418.     Me.chkCommentOnly.Enabled = True
  419. End If
  420. Exit Sub
  421. ' Error Routine
  422. chkCommentTemplate_Click_Error:
  423. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In chkCommentTemplate_Click"
  424. End Sub
  425. Private Sub Form_Load()
  426. ' Procedure Form_Load
  427. ' ----------------------------------------------------------------------
  428. ' Author        : Mark Kirkland
  429. ' Organisation  : Brighton Health Care NHS Trust
  430. ' Date          : 01/10/1998
  431. ' Description   :
  432. ' Amendments    :
  433. ' Error Handler
  434. On Error GoTo Form_Load_Error:
  435. ' Declare variables
  436. Dim strAuthor As String
  437. Dim strOrganisation As String
  438. ' Get the author from the system registry
  439. strAuthor = GetSetting(APP_NAME, "Author Details", "Author", "Mark Kirkland")
  440. Me.txtAuthor.Text = strAuthor
  441. ' Get the organisation from the system registry
  442. strOrganisation = GetSetting(APP_NAME, "Author Details", "Organisation", "Brighton Health Care")
  443. Me.txtOrganisation.Text = strOrganisation
  444. Exit Sub
  445. ' Error Routine
  446. Form_Load_Error:
  447. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In Form_Load"
  448. End Sub
  449. Private Sub cmdDeleteParams_Click()
  450. ' Procedure cmdDeleteParams_Click
  451. ' ----------------------------------------------------------------------
  452. ' Author        : Mark Kirkland
  453. ' Organisation  : Brighton Health Care NHS Trust
  454. ' Date          : 30/09/1998
  455. ' Description   :
  456. ' Amendments    :
  457. ' Error Handler
  458. On Error GoTo cmdDeleteParams_Click_Error:
  459. ' Variable Declarations
  460. Dim I As Integer
  461. Dim intSelectedList As Integer
  462. Dim strSelectedKey As String
  463. ' Remove the parameters from the listview
  464. strSelectedKey = Me.lvParameters.SelectedItem.Key
  465. Me.lvParameters.ListItems.Remove strSelectedKey
  466. Exit Sub
  467. ' Error Routine
  468. cmdDeleteParams_Click_Error:
  469. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In cmdDeleteParams_Click"
  470. End Sub
  471. Private Sub CancelButton_Click()
  472. ' Procedure CancelButton_Click
  473. ' ----------------------------------------------------------------------
  474. ' Author        : Mark Kirkland
  475. ' Organisation  : Brighton Health Care NHS Trust
  476. ' Date          : 29/09/1998
  477. ' Description   : Clears and then hides the form on cancel
  478. ' Amendments    :
  479. ' Error Handler
  480. On Error GoTo CancelButton_Click_Error:
  481. ' Declare variables
  482. Dim strAuthor
  483. Dim strOrganisation
  484.     ' Check the registry settings and if necessary amend them
  485.     ' First for the author
  486.     If Len(Me.txtAuthor.Text) > 0 Then
  487.         ' First check tha author settings
  488.         strAuthor = GetSetting(APP_NAME, "Author Details", "Author", "Mark Kirkland")
  489.         ' If the settings on the form differ then amend the registry
  490.         If Trim$(strAuthor) <> Trim$(Me.txtAuthor.Text) Then
  491.             SaveSetting APP_NAME, "Author Details", "Author", Trim$(Me.txtAuthor.Text)
  492.         End If
  493.     End If
  494.     ' And next for the organisation
  495.     If Len(Me.txtOrganisation.Text) > 0 Then
  496.         ' First check tha organisation settings
  497.         strOrganisation = GetSetting(APP_NAME, "Author Details", "Organisation", "Brighton Health Care")
  498.         ' If the settings on the form differ then amend the registry
  499.         If Trim$(strOrganisation) <> Trim$(Me.txtOrganisation.Text) Then
  500.             SaveSetting APP_NAME, "Author Details", "Organisation", Trim$(Me.txtOrganisation.Text)
  501.         End If
  502.     End If
  503.     ' Now clear the form to the default display
  504.     Call ClearForm
  505.     Connect.Hide
  506. Exit Sub
  507. ' Error Routine
  508. CancelButton_Click_Error:
  509. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CancelButton_Click"
  510. End Sub
  511. Private Function CheckOptional() As Boolean
  512. ' Function CheckOptional
  513. ' ----------------------------------------------------------------------
  514. ' Author        : Mark Kirkland
  515. ' Organisation  : Brighton Health Care NHS Trust
  516. ' Date          : 29/09/1998
  517. ' Description   : Checks through the lvParameters listview control and ascertains
  518. '                 whether any of the parameters that have already been entered are
  519. '                 optional. If so then all other parameters should also be optional
  520. ' Amendments    :
  521. ' Error Handler
  522. On Error GoTo CheckOptional_Error:
  523. ' Declare variables
  524. Dim I As Integer    ' throwaway variable
  525. Dim intListCount As Integer
  526. ' Initialise variables
  527. intListCount = Me.lvParameters.ListItems.Count
  528. ' Check whether any parameters have been given
  529. If intListCount > 0 Then
  530.     For I = 1 To intListCount
  531.         If Me.lvParameters.ListItems.Item(I).SubItems(3) = "True" Then
  532.             CheckOptional = True
  533.         End If
  534.     Next I
  535. End If
  536.         
  537. Exit Function
  538. ' Error Routine
  539. CheckOptional_Error:
  540. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CheckOptional"
  541. CheckOptional = False
  542. End Function
  543. Private Function CreateErrorHandler() As String
  544. ' Function CreateErrorHandler
  545. ' ----------------------------------------------------------------------
  546. ' Author        : Mark Kirkland
  547. ' Organisation  : Brighton Health Care NHS Trust
  548. ' Date          : 29/09/1998
  549. ' Description   :
  550. ' Amendments    :
  551. ' Error Handler
  552. On Error GoTo CreateErrorHandler_Error:
  553. ' Variable Declaration
  554. Dim strOutput As String
  555.     If Me.chkErrorHandling.Value = vbChecked Then
  556.         ' Add the on error statement
  557.         strOutput = strOutput & vbCrLf & "' Error Handler" & vbCrLf
  558.         strOutput = strOutput & "On Error Goto " & Me.txtName.Text _
  559.         & "_Error: "
  560.         ' Mark where the user starts to place code
  561.         strOutput = strOutput & vbCrLf & vbCrLf & "' PLACE CODE HERE !!!!!" & vbCrLf & vbCrLf
  562.         If Me.optFunction.Value = True Then
  563.         strOutput = strOutput & "Exit Function"
  564.         Else
  565.            strOutput = strOutput & "Exit Sub"
  566.         End If
  567.         ' Add the error handler label. What is added depends on whether we are in a
  568.         ' class module or not.
  569.         If VBC.Type = vbext_ct_ClassModule Then
  570.             strOutput = strOutput & vbCrLf & vbCrLf & "' Error Routine " & vbCrLf & _
  571.             Me.txtName.Text & "_Error:" & vbCrLf _
  572.             & "Err.Raise Err.Number, " & """" & Me.txtName.Text & """" & ", Err.Description" _
  573.             & vbCrLf
  574.         Else
  575.             strOutput = strOutput & vbCrLf & vbCrLf & "' Error Routine " & vbCrLf & _
  576.             Me.txtName.Text & "_Error:" & vbCrLf _
  577.             & "msgbox ""Error # "" & Err.Number & "": "" & Err.Description & "" In " & Trim$(Me.txtName.Text) & """" _
  578.             & vbCrLf
  579.         End If
  580.     End If
  581. ' Return string back from function
  582. CreateErrorHandler = strOutput
  583. Exit Function
  584. ' Error Routine
  585. CreateErrorHandler_Error:
  586. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CreateErrorHandler"
  587. CreateErrorHandler = "" ' Function failed so return an empty string
  588. End Function
  589. Private Function CreateComments(Author As String, Organisation As String _
  590. , ProcedureName As String, TypeOfProc As String) As String
  591. ' Function CreateComments
  592. ' ----------------------------------------------------------------------
  593. ' Author        : Mark Kirkland
  594. ' Organisation  : Brighton Health Care NHS Trust
  595. ' Date          : 29/09/1998
  596. ' Description   :
  597. ' Amendments    :
  598. ' Error Handler
  599. On Error GoTo CreateComments_Error:
  600. ' Declare variables
  601. Dim strOutput As String
  602. Dim I As Integer        ' Throwaway variable
  603. Dim strAuthor As String
  604. Dim strOrganisation As String
  605. ' Initialise variables
  606. strAuthor = Author
  607. strOrganisation = Organisation
  608.     If Me.chkCommentTemplate.Value = vbChecked Then
  609.         ' Fill in the type of procedure
  610.         strOutput = strOutput & vbCrLf & "' " & TypeOfProc & " " & ProcedureName & vbCrLf
  611.         ' Write a blank comment line
  612.         strOutput = strOutput & "' "
  613.         ' And write a line with 70 dashes "-" on it
  614.         For I = 1 To 70
  615.             strOutput = strOutput & "-"
  616.         Next I
  617.         ' Write a comment for the program author
  618.         strOutput = strOutput & vbCrLf & "' Author" & vbTab & vbTab & ": " _
  619.         & strAuthor & vbCrLf
  620.         ' Write comment for the organisation
  621.         strOutput = strOutput & "' Organisation " & vbTab & ": " & strOrganisation _
  622.         & vbCrLf
  623.         ' Write comment for the date
  624.         strOutput = strOutput & "' Date " & vbTab & vbTab & vbTab & ": " & Format$(Date, "dd/mm/yyyy") _
  625.         & vbCrLf
  626.         ' Add a blank comment line
  627.         strOutput = strOutput & "'" & vbCrLf
  628.         ' Add the description comment
  629.         strOutput = strOutput & "' Description" & vbTab & ":" & vbCrLf
  630.         ' Add a blank line
  631.         strOutput = strOutput & "'" & vbCrLf
  632.         ' Add the amendments comment
  633.         strOutput = strOutput & "' Amendments" & vbTab & ":" & vbCrLf
  634.         ' Add a blank line
  635.         strOutput = strOutput & "'" & vbCrLf
  636.     End If
  637.     ' Only place if there has been no error handling selected otherwise the
  638.     ' CreateErrorHandler function will write this line
  639.     If Me.chkErrorHandling.Value = vbUnchecked Then
  640.         strOutput = strOutput & vbCrLf & vbCrLf & "' PLACE CODE HERE !!!!!" & vbCrLf & vbCrLf
  641.     End If
  642. ' Pass the value back out of the function
  643. CreateComments = strOutput
  644. Exit Function
  645. ' Error Routine
  646. CreateComments_Error:
  647. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CreateComments"
  648. CreateComments = ""     ' Function failed so return an empty string
  649. End Function
  650. Private Sub ClearForm()
  651. ' Procedure ClearForm
  652. ' ----------------------------------------------------------------------
  653. ' Author        : Mark Kirkland
  654. ' Organisation  : Brighton Health Care (NHS) Trust
  655. ' Date          : 29/09/1998
  656. ' Description   :
  657. ' Amendments    :
  658. ' Error Handler
  659. On Error GoTo ClearForm_Error:
  660. Dim ctlFormControls As Control
  661. ' Reset the form to the default values
  662. For Each ctlFormControls In Me.Controls
  663.     ' Clear all the textboxes Text property
  664.     If TypeOf ctlFormControls Is TextBox Or TypeOf ctlFormControls Is ComboBox Then
  665.         If ctlFormControls.Name <> "txtOrganisation" And ctlFormControls.Name <> "txtAuthor" Then
  666.             ctlFormControls.Text = ""
  667.         End If
  668.     ' Check the Procedure and Public option buttons and uncheck the rest
  669.     ElseIf TypeOf ctlFormControls Is OptionButton Then
  670.         If ctlFormControls.Name = "optProcedure" Or ctlFormControls.Name = "optPublic" Then
  671.             ctlFormControls.Value = True
  672.         Else
  673.             ctlFormControls.Value = False
  674.         End If
  675.     ' Check error handling and comment template checkboxes by default
  676.     ElseIf TypeOf ctlFormControls Is CheckBox Then
  677.         If ctlFormControls.Name = "chkCommentTemplate" Or ctlFormControls.Name = "chkErrorHandling" Then
  678.             ctlFormControls.Value = vbChecked
  679.         Else
  680.             ctlFormControls.Value = vbUnchecked
  681.         End If
  682.     ' Clear the listview control
  683.     ElseIf TypeOf ctlFormControls Is ListView Then
  684.         ctlFormControls.ListItems.Clear
  685.     End If
  686. Exit Sub
  687. ' Error Routine
  688. ClearForm_Error:
  689. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In ClearForm"
  690. End Sub
  691. Private Function CreateHeader() As String
  692. ' Function CreateHeader
  693. ' ----------------------------------------------------------------------
  694. ' Author        : Mark Kirkland
  695. ' Organisation  : Brighton Healthcare NHS Trust
  696. ' Date          : 29/09/1998
  697. ' Description   : Creates the string creating the sub or function header details
  698. '               : The function takes information from the frmProcedureBuilder form
  699. '               : Returns a string containing this information
  700. ' Amendments    :
  701. ' Error Handler
  702. On Error GoTo CreateHeader_Error
  703. ' Declare variables
  704. Dim strOutput As String ' String containing header information for procedure
  705. Dim I As Integer ' Throwaway variable
  706.     ' Now build the procedure definition starting with whether the procedure is
  707.     ' private or public
  708.     If Me.optPrivate.Value = True Then
  709.         strOutput = "Private "
  710.     ElseIf Me.optPublic.Value = True Then
  711.         strOutput = "Public "
  712.     ElseIf Me.optFriend.Value = True Then
  713.         ' If a friend procedure is declared then check we are in a class module
  714.         If VBC.Type = vbext_ct_ClassModule Then
  715.             strOutput = "Friend "
  716.         Else
  717.             MsgBox "You can only use Friend in a Class Module" & vbCrLf & _
  718.             "Defaulting to Private", vbInformation
  719.             strOutput = "Private "
  720.         End If
  721.     End If
  722.     ' Check whether this is a static procedure
  723.     If Me.chkStatic.Value = vbChecked Then
  724.         strOutput = strOutput & "Static "
  725.     End If
  726.     ' Now find out whether this is a procedure or a function
  727.     ' This is a function
  728.     If Me.optFunction.Value = True Then
  729.         strOutput = strOutput & "Function " & Me.txtName.Text & " ("
  730.         ' If parameters have been specified then include them in the header
  731.         If Me.lvParameters.ListItems.Count > 0 Then
  732.             For I = 1 To Me.lvParameters.ListItems.Count
  733.                 If Me.lvParameters.ListItems(I).SubItems(3) = "True" Then
  734.                     strOutput = strOutput & "Optional "
  735.                 End If
  736.                 If Trim$(Me.lvParameters.ListItems(I).SubItems(2)) = "ByVal" Then
  737.                     strOutput = strOutput & "ByVal "
  738.                 End If
  739.                 strOutput = strOutput & Me.lvParameters.ListItems(I).Key & " As " & _
  740.                 Me.lvParameters.ListItems(I).SubItems(1)
  741.                 ' Only add a comma if there is more than one parameter
  742.                 If I <> Me.lvParameters.ListItems.Count _
  743.                 And Me.lvParameters.ListItems.Count > 1 Then
  744.                         ' Separate the parameters with a comma
  745.                         strOutput = strOutput & ", "
  746.                 End If
  747.             Next I
  748.         End If
  749.         ' Add the return parameter type
  750.         strOutput = strOutput & ") As " _
  751.         & Trim$(Me.cmbReturnType.Text) & vbCrLf
  752.     ' This is a subroutine
  753.     Else
  754.         strOutput = strOutput & "Sub " & Me.txtName.Text & " ("
  755.         If Me.lvParameters.ListItems.Count > 0 Then
  756.             For I = 1 To Me.lvParameters.ListItems.Count
  757.                 If Me.lvParameters.ListItems(I).SubItems(3) = "True" Then
  758.                     strOutput = strOutput & "Optional "
  759.                 End If
  760.                 If Trim$(Me.lvParameters.ListItems(I).SubItems(2)) = "ByVal" Then
  761.                     strOutput = strOutput & "ByVal "
  762.                 End If
  763.                 strOutput = strOutput & Me.lvParameters.ListItems(I).Key & " As " & _
  764.                 Me.lvParameters.ListItems(I).SubItems(1)
  765.                 If I <> Me.lvParameters.ListItems.Count Then
  766.                     ' Only add a comma if there is more than one parameter
  767.                     If Me.lvParameters.ListItems.Count > 1 Then
  768.                         ' Separate the parameters with a comma
  769.                         strOutput = strOutput & ", "
  770.                     End If
  771.                 End If
  772.             Next I
  773.         End If
  774.         ' And add the final parenthesis
  775.         strOutput = strOutput & ")" & vbCrLf
  776.     End If
  777. ' Return the string for the program header
  778. CreateHeader = strOutput
  779. Exit Function
  780. ' Error Routine
  781. CreateHeader_Error:
  782. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CreateHeader"
  783. ' Error so return empty string
  784. CreateHeader = ""
  785. End Function
  786. Private Sub cmdAdd_Click()
  787. ' Procedure cmdAdd_Click
  788. ' ----------------------------------------------------------------------
  789. ' Author        :
  790. ' Organisation  :
  791. ' Date          : 28/09/1998
  792. ' Description   :
  793. ' Amendments    :
  794. ' Error Handler
  795. On Error GoTo cmdAdd_Click_Error:
  796. ' Declare variables
  797. Dim booOptional As Boolean
  798. Dim itmlist As ListItem
  799. ' Ensure that both the parameter name and type box are completed
  800. If Len(Me.txtParameterName.Text) <> 0 Then
  801.     If Me.cmbParameterType.Text = "" Then
  802.         MsgBox "You Must Select a Parameter Type"
  803.         Exit Sub
  804.     End If
  805. End If
  806. If Len(Me.cmbParameterType.Text) <> 0 Then
  807.     If Me.txtParameterName.Text = "" Then
  808.         MsgBox "You Must Select a Parameter Name"
  809.         Exit Sub
  810.     End If
  811. End If
  812. If Len(Me.txtParameterName.Text) = 0 Then
  813.     MsgBox "You Must Select a Parameter Name"
  814.     Exit Sub
  815. End If
  816. If Len(Me.cmbParameterType.Text) = 0 Then
  817.     MsgBox "You Must Select a Parameter Type"
  818.     Exit Sub
  819. End If
  820. ' Add the parameter to the listview
  821. Set itmlist = Me.lvParameters.ListItems.Add(Key:=Me.txtParameterName.Text)
  822. With itmlist
  823.     .Text = Me.txtParameterName.Text
  824.     .SubItems(1) = Me.cmbParameterType.Text
  825.     If Len(Me.cmbByRef.Text) > 0 Then
  826.         .SubItems(2) = Me.cmbByRef.Text
  827.     Else
  828.         .SubItems(2) = "ByRef"
  829.     End If
  830.     If Me.chkOptional.Value = vbChecked Then
  831.         .SubItems(3) = "True"
  832.     Else
  833.         ' Check to see if any parameters have been included as optional
  834.         ' in which case all other parameters will need to be optional too
  835.         booOptional = CheckOptional
  836.         If booOptional Then
  837.             .SubItems(3) = "True"
  838.         Else
  839.             .SubItems(3) = "False"
  840.         End If
  841.     End If
  842. End With
  843. ' And clear the textbox and listboxes for new input
  844. Me.txtParameterName.Text = ""
  845. Me.cmbParameterType.Text = ""
  846. Me.cmbByRef.Text = ""
  847. Me.chkOptional.Value = vbUnchecked
  848. Exit Sub
  849. ' Error Routine
  850. cmdAdd_Click_Error:
  851. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In cmdAdd_Click"
  852. End Sub
  853. Private Sub OKButton_Click()
  854. ' Procedure OKButton_Click
  855. ' ----------------------------------------------------------------------
  856. ' Author        : Mark Kirkland
  857. ' Organisation  : Brighton Health Care NHS Trust
  858. ' Date          : 12/01/1999
  859. ' Description   : Main routine for building the subroutine or function
  860. ' Amendments    :
  861. ' Declare variables
  862. ' Error Handler
  863. On Error GoTo OKButton_Click_Error
  864. Dim Counter As Integer  ' Loop counter
  865. Dim intTop As Integer
  866. Dim strProc As String       ' Contains the code for the method to be inserted into the current code pane
  867. Dim I As Integer                ' Throwaway variable
  868. Dim strAuthor As String     ' Author of the procedure
  869. Dim strOrganisation As String   ' Organisation of the author (both these values can be changed and are stored in the registry)
  870. Dim strCurrentProcedure As String
  871. Dim booPropertyProcedure As Boolean
  872. ' Initialise property procedure boolean. Used to flag whether we are in a property
  873. ' procedure or not
  874. booPropertyProcedure = False
  875. ' Check the registry settings and if necessary amend them
  876. ' First for the author
  877. If Len(Me.txtAuthor.Text) > 0 Then
  878.     ' First check tha author settings
  879.     strAuthor = GetSetting(APP_NAME, "Author Details", "Author", "Mark Kirkland")
  880.     ' If the settings on the form differ then amend the registry
  881.     If Trim$(strAuthor) <> Trim$(Me.txtAuthor.Text) Then
  882.         SaveSetting APP_NAME, "Author Details", "Author", Trim$(Me.txtAuthor.Text)
  883.     End If
  884. End If
  885. ' And next for the organisation
  886. If Len(Me.txtOrganisation.Text) > 0 Then
  887.     ' First check tha organisation settings
  888.     strOrganisation = GetSetting(APP_NAME, "Author Details", "Organisation", "Brighton Health Care")
  889.     ' If the settings on the form differ then amend the registry
  890.     If Trim$(strOrganisation) <> Trim$(Me.txtOrganisation.Text) Then
  891.         SaveSetting APP_NAME, "Author Details", "Organisation", Trim$(Me.txtOrganisation.Text)
  892.     End If
  893. End If
  894. ' Check that a parameter hasn't been entered and the user forgotten about it
  895. If Len(Me.txtParameterName.Text) > 0 Then
  896.     Call cmdAdd_Click
  897. End If
  898. ' Find out which codepane is active
  899. Set cpActCodePane = VBInstance.ActiveCodePane
  900. ' And get the active code module
  901. Set cmCodeModule = cpActCodePane.CodeModule
  902. ' First check whether or not only a comment template is required
  903. If Me.chkCommentOnly.Value = vbChecked And Me.chkCommentOnly.Enabled = True Then
  904.     Call CreateCommentTemplateOnly
  905. End If
  906. ' Then check whether or not only a generic error handler is required
  907. If Me.chkErrorOnly.Value = vbChecked And Me.chkErrorOnly.Enabled = True Then
  908.     Call CreateErrorHandlerOnly
  909. End If
  910. ' Exit this procedure if either of the Comment Only or Error Only checkboxes
  911. ' was selected
  912. If Me.chkCommentOnly.Value = vbChecked Or Me.chkErrorOnly.Value = vbChecked Then
  913.     ' Clear the form to the default display
  914.     Call ClearForm
  915.     ' And tidy up the objects and close the form
  916.     Set cpActCodePane = Nothing
  917.     Set cmCodeModule = Nothing
  918.     Connect.Hide
  919.     Exit Sub
  920. End If
  921. ' Then ascertain whether a procedure name has been given or not
  922. If Me.txtName.Text = "" Then
  923.     MsgBox "Must Give a Procedure Name"
  924.     Me.txtName.SetFocus
  925.     Exit Sub
  926.     ' If building a function then ensure that a return type is given
  927.     ' N.B. Decimal is currently not supported so is not an option
  928.     If Me.optFunction.Value = True Then
  929.         If Len(Me.cmbReturnType.Text) = 0 Then
  930.             MsgBox "Must Have a Function Return Type"
  931.             Me.cmbReturnType.SetFocus
  932.             Exit Sub
  933.         End If
  934.     End If
  935. End If
  936.         
  937. ' Now build the procedure definition starting with the header
  938. strProc = CreateHeader
  939. ' Next add the comment template if required
  940. ' -----------------------------------------------------------------------------------
  941. If Me.optFunction.Value = True Then
  942.     strProc = strProc & CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  943. , Me.txtName, "Function")
  944. ElseIf Me.optFriend.Value = True Then
  945.     strProc = strProc & CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  946.     , Me.txtName, "Friend")
  947. ElseIf Me.optProcedure = True Then
  948.     strProc = strProc & CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  949.     , Me.txtName, "Sub")
  950. End If
  951. ' Add the error handling if specified
  952. ' -----------------------------------------------------------------------------------
  953. strProc = strProc & CreateErrorHandler
  954. ' And add the end sub/function
  955. ' -----------------------------------------------------------------------------------
  956. If Me.optFunction.Value = True Then
  957.     strProc = strProc & vbCrLf & "End Function"
  958.     strProc = strProc & vbCrLf & "End Sub"
  959. End If
  960. ' And write to the code window
  961. cmCodeModule.AddFromString strProc
  962. ' Get the first line of the added procedure by moving to the first line after the
  963. ' declarations section
  964. Dim lngFromLine As Long
  965. lngFromLine = 1 + cmCodeModule.CountOfDeclarationLines
  966. ' Now select the line where the first code will be inserted. Use an arbitrary
  967. ' value of 100 lines since the procedure template generated will never be this
  968. ' long. We are starting after the declarations section and since we used AddFromString
  969. ' we know that this will be the first line of the new procedure template
  970. If cmCodeModule.Find("' PLACE CODE HERE !!!!!", lngFromLine, 1, 100, 1) Then
  971.     cpActCodePane.SetSelection lngFromLine, 1, lngFromLine, 100
  972. End If
  973. cpActCodePane.Show
  974. ' Now clear the form to the default display
  975. Call ClearForm
  976. ' And tidy up the objects and close the form
  977. Set cpActCodePane = Nothing
  978. Set cmCodeModule = Nothing
  979. Connect.Hide
  980. Exit Sub
  981. ' Error Routine
  982. OKButton_Click_Error:
  983. If Err.Number = 35 Then
  984.     ' Check for error 35 so we can recognise property functions in classes
  985.     Resume Next
  986.     MsgBox "Error # " & Err.Number & ": " & Err.Description & " In OKButton_Click"
  987. End If
  988. End Sub
  989. Private Sub optFriend_Click()
  990. ' Procedure optFriend_Click
  991. ' ----------------------------------------------------------------------
  992. ' Author        : Mark Kirkland
  993. ' Organisation  : Brighton Health Care NHS Trust
  994. ' Date          : 12/01/1999
  995. ' Description   :
  996. ' Amendments    :
  997. ' Error Handler
  998. On Error GoTo optFriend_Click_Error
  999. ' If a friend procedure is declared then check we are in a class module
  1000. If VBC.Type <> vbext_ct_ClassModule Then
  1001.     MsgBox "You can only use Friend in a Class Module", vbInformation
  1002.     Me.optFriend.Value = False
  1003. End If
  1004. Exit Sub
  1005. ' Error Routine
  1006. optFriend_Click_Error:
  1007. MsgBox "Error # " & Err.Number & ": " & Err.Description & " In optFriend_Click"
  1008. End Sub
  1009. Private Sub optFunction_Click()
  1010. ' Error Handler
  1011. On Error GoTo optFunction_Click_Error
  1012. ' If a function is selected then make the return type combo box visible
  1013. If Me.optFunction.Value = True Then
  1014.     Me.lblReturnType.Visible = True
  1015.     Me.cmbReturnType.Visible = True
  1016.     Me.lblReturnType.Visible = False
  1017.     Me.cmbReturnType.Visible = False
  1018. End If
  1019. ' Successful Routine
  1020. Exit Sub
  1021. ' Error Routine
  1022. optFunction_Click_Error:
  1023. MsgBox "Error #" & Err.Number & " : " & Err.Description & " In optFunction_Click"
  1024. End Sub
  1025. Private Sub optProcedure_Click()
  1026. ' Error Handler
  1027. On Error GoTo optProcedure_Click_Error
  1028. ' If a function is selected then make the return type combo box visible
  1029. ' otherwise hide it
  1030. If Me.optProcedure.Value = True Then
  1031.     Me.lblReturnType.Visible = False
  1032.     Me.cmbReturnType.Visible = False
  1033.     Me.lblReturnType.Visible = True
  1034.     Me.cmbReturnType.Visible = True
  1035. End If
  1036. ' Successful Routine
  1037. Exit Sub
  1038. ' Error Routine
  1039. optProcedure_Click_Error:
  1040. MsgBox "Error #" & Err.Number & " : " & Err.Description & " In optProcedure_Click"
  1041. End Sub
  1042. Private Sub txtName_LostFocus()
  1043. ' Error Handler
  1044. On Error GoTo txtName_Error
  1045. ' Check that there are no spaces in the function or procedure name
  1046. If Not NoSpaces(Me.txtName.Text) Then
  1047.     MsgBox "Spaces Not allowed in Procedure Names"
  1048.     Me.txtName.SetFocus
  1049. End If
  1050. ' Success
  1051. Exit Sub
  1052. ' Error Routine
  1053. txtName_Error:
  1054. MsgBox "Error: " & Err.Number & " - " & Err.Description & " txtName_LostFocus"
  1055. End Sub
  1056. Private Sub CreateCommentTemplateOnly()
  1057. ' Sub CreateCommentTemplateOnly
  1058. ' ----------------------------------------------------------------------
  1059. ' Author        : Mark Kirkland
  1060. ' Organisation  : Brighton Health Care NHS Trust
  1061. ' Date          : 27/01/1999
  1062. ' Description   :
  1063. ' Amendments    :
  1064. ' Error Handler
  1065. On Error GoTo CreateCommentTemplateOnly_Error
  1066. ' Declare variables
  1067. Dim strProcName As String
  1068. Dim lngFirstLine As Long
  1069. Dim lngFirstColumn As Long
  1070. Dim lngLastLine As Long
  1071. Dim lngLastColumn As Long
  1072. Dim lngProcFirstLine As String
  1073. Dim lngProcFirstLineGet As Long
  1074. Dim lngProcFirstLineLet As Long
  1075. Dim lngProcFirstLineSet As Long
  1076. Dim lngGet As Long
  1077. Dim lngSet As Long
  1078. Dim lngLet As Long
  1079. Dim strLine As String
  1080. Dim strProc As String
  1081.    ' Find out what line we are on at the moment
  1082.     cpActCodePane.GetSelection lngFirstLine, lngFirstColumn, lngLastLine, lngLastColumn
  1083.     ' And get the procedure name that we are in at the moment
  1084.     strProcName = cmCodeModule.ProcOfLine(lngFirstLine, vbext_pk_Proc)
  1085.     ' Now get the first line of this procedure or function
  1086.     ' A check will be done in the error handler for error 35 so regardless
  1087.     ' of which type of procedure the cursor is on we will be able to get the
  1088.     ' first line for it.
  1089.     ' Now check whether this is a subroutine a function or a property procedure
  1090.     lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1091.     lngProcFirstLineGet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Get)
  1092.     lngProcFirstLineLet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Let)
  1093.     lngProcFirstLineSet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Set)
  1094.     ' Unfortunately if error 35 is raised for vbext_pk_prop then all of the others
  1095.     ' will be set. So we find out which one is  closest to our current line.
  1096.     ' There must be an easier way to do this.........!!!!@@@@########*****
  1097.     lngGet = lngFirstLine - lngProcFirstLineGet
  1098.     lngSet = lngFirstLine - lngProcFirstLineSet
  1099.     lngLet = lngFirstLine - lngProcFirstLineLet
  1100.     ' We check which of the three variables lngGet, lngSet or lngLet is the smallest
  1101.     ' (and therefore closest to the current cursor position) taking into account the
  1102.     ' fact that the values could be negative. What a pain ...***###@@@!!! etc
  1103.     ' IF ANYONE KNOWS OF A NICE EASY WAY TO TELL WHETHER THE CURRENT CURSOR IS ON A
  1104.     ' PROPERTY LET,SET OR GET THEN PLEASE LET ME KNOW !!!!
  1105.     If (lngGet < IIf(lngSet < 0, lngGet + 1, lngSet)) And (lngGet < IIf(lngLet < 0, lngGet + 1, lngLet)) And (lngGet > 0) Then
  1106.         ' Procedure is property get
  1107.         lngProcFirstLine = lngProcFirstLineGet
  1108.     ElseIf (lngSet < IIf(lngGet < 0, lngSet + 1, lngGet)) And (lngSet < IIf(lngLet < 0, lngSet + 1, lngLet)) And (lngSet > 0) Then
  1109.         ' Procedure is property set
  1110.         lngProcFirstLine = lngProcFirstLineSet
  1111.     ElseIf (lngLet < IIf(lngGet < 0, lngLet + 1, lngGet)) And (lngLet < IIf(lngSet < 0, lngLet + 1, lngSet)) And (lngLet > 0) Then
  1112.         ' Procedure is property let
  1113.         lngProcFirstLine = lngProcFirstLineLet
  1114.     End If
  1115.     ' And finally we can get the first line of the procedure
  1116.     strLine = cmCodeModule.Lines(lngProcFirstLine, 1)
  1117.     ' Now check whether this is a subroutine a function or a property procedure
  1118.     If InStr(1, strLine, "Sub") Then
  1119.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1120.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1121.         , strProcName, "Sub")
  1122.     ElseIf InStr(1, strLine, "Function") Then
  1123.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1124.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1125.         , strProcName, "Function")
  1126.     ElseIf InStr(1, strLine, "Friend") Then
  1127.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1128.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1129.         , strProcName, "Friend")
  1130.     ElseIf InStr(1, strLine, "Property Get") Then
  1131.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Get)
  1132.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1133.         , strProcName, "Property Get")
  1134.     ElseIf InStr(1, strLine, "Property Set") Then
  1135.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Set)
  1136.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1137.         , strProcName, "Property Set")
  1138.     ElseIf InStr(1, strLine, "Property Let") Then
  1139.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Let)
  1140.         strProc = CreateComments(Trim$(Me.txtAuthor.Text), Trim$(Me.txtOrganisation.Text) _
  1141.         , strProcName, "Property Let")
  1142.     Else
  1143.         ' Generic error message
  1144.         MsgBox "Unrecognised routine type"
  1145.         Exit Sub
  1146.     End If
  1147.     ' Now create the comment template
  1148.     cmCodeModule.InsertLines lngProcFirstLine + 1, strProc
  1149. Exit Sub
  1150. ' Error Routine
  1151. CreateCommentTemplateOnly_Error:
  1152. If Err.Number = 35 Then
  1153.     ' Check for error 35 so we can recognise property functions in classes
  1154.     Resume Next
  1155.     MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CreateCommentTemplateOnly"
  1156. End If
  1157. End Sub
  1158. Private Sub CreateErrorHandlerOnly()
  1159. ' Sub CreateErrorHandlerOnly
  1160. ' ----------------------------------------------------------------------
  1161. ' Author        :
  1162. ' Organisation  :
  1163. ' Date          : 27/01/1999
  1164. ' Description   :   This routine creates and places in the routine under the cursor an error handler only. Used for existing
  1165. '                               routines where a generic error handler needs to be added after the the routine has been created
  1166. ' Amendments    :
  1167. ' Error Handler
  1168. On Error GoTo CreateErrorHandlerOnly_Error
  1169. ' Declare variables
  1170. Dim strProcName As String                           ' Name of the procedure
  1171. Dim lngFirstLine As Long                                ' First line of the procedure that the cursor is on
  1172. Dim lngFirstColumn As Long                          ' First column of the procedure that the cursor is on
  1173. ' We are not really interested in the following two variables. They are included because they are required parameters
  1174. ' to the GetSelection method of the active code pane. Even if a selection of text was highlighted, the program would ignore
  1175. ' this
  1176. Dim lngLastLine As Long
  1177. Dim lngLastColumn As Long
  1178. Dim lngCurrentLine As Long                          ' Stores the current line of the procedure as we move about in it
  1179. ' The following variables get the first line of the procedure and take into account whether the procedure is a property
  1180. ' procedure or a standard function or sub. This is a total kludge and there must be an easier way to do it.
  1181. Dim lngProcFirstLine As String
  1182. Dim lngProcFirstLineGet As Long
  1183. Dim lngProcFirstLineLet As Long
  1184. Dim lngProcFirstLineSet As Long
  1185. Dim lngGet As Long
  1186. Dim lngSet As Long
  1187. Dim lngLet As Long
  1188. Dim strLine As String                                       ' Holds the current line
  1189. Dim strProc As String                                       ' Holds the error handler template
  1190. Dim strFunctionType As String                   ' Holds the type of method (function,sub etc). This is added to the template
  1191. Dim booInsertError As Boolean               ' Used to throw us out of the loop which ascertains where the error handler is to be
  1192.                                                                             ' inserted
  1193. Dim I As Integer                                                ' Throwaway variable
  1194. Dim strCurrentCharacter  As String           ' Holds each character in the current line. Used to check where the error handler
  1195.                                                                             ' will be inserted
  1196.     ' Find out what line we are on at the moment
  1197.     cpActCodePane.GetSelection lngFirstLine, lngFirstColumn, lngLastLine, lngLastColumn
  1198.     ' And get the procedure name that we are in at the moment
  1199.     strProcName = cmCodeModule.ProcOfLine(lngFirstLine, vbext_pk_Proc)
  1200.     ' Now get the first line of this procedure or function
  1201.     ' A check will be done in the error handler for error 35 so regardless
  1202.     ' of which type of procedure the cursor is on we will be able to get the
  1203.     ' first line for it
  1204.     lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1205.     lngProcFirstLineGet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Get)
  1206.     lngProcFirstLineLet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Let)
  1207.     lngProcFirstLineSet = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Set)
  1208.     ' Unfortunately if error 35 is raised for vbext_pk_prop then all of the others
  1209.     ' will be set. So we find out which one is  closest to our current line.
  1210.     ' There must be an easier way to do this.........!!!!@@@@########*****
  1211.     lngGet = lngFirstLine - lngProcFirstLineGet
  1212.     lngSet = lngFirstLine - lngProcFirstLineSet
  1213.     lngLet = lngFirstLine - lngProcFirstLineLet
  1214.     ' We check which of the three variables lngGet, lngSet or lngLet is the smallest
  1215.     ' (and therefore closest to the current cursor position) taking into account the
  1216.     ' fact that the values could be negative. What a pain ...***###@@@!!! etc
  1217.     ' IF ANYONE KNOWS OF A NICE EASY WAY TO TELL WHETHER THE CURRENT CURSOR IS ON A
  1218.     ' PROPERTY LET,SET OR GET THEN PLEASE LET ME KNOW !!!!
  1219.     If (lngGet < IIf(lngSet < 0, lngGet + 1, lngSet)) And (lngGet < IIf(lngLet < 0, lngGet + 1, lngLet)) And (lngGet > 0) Then
  1220.         ' Procedure is property get
  1221.         lngProcFirstLine = lngProcFirstLineGet
  1222.     ElseIf (lngSet < IIf(lngGet < 0, lngSet + 1, lngGet)) And (lngSet < IIf(lngLet < 0, lngSet + 1, lngLet)) And (lngSet > 0) Then
  1223.         ' Procedure is property set
  1224.         lngProcFirstLine = lngProcFirstLineSet
  1225.     ElseIf (lngLet < IIf(lngGet < 0, lngLet + 1, lngGet)) And (lngLet < IIf(lngSet < 0, lngLet + 1, lngSet)) And (lngLet > 0) Then
  1226.         ' Procedure is property let
  1227.         lngProcFirstLine = lngProcFirstLineLet
  1228.     End If
  1229.     ' Now check whether this line is a blank line or a comment line
  1230.     strLine = cmCodeModule.Lines(lngProcFirstLine, 1)
  1231.     ' And finally we can get the first line of the procedure
  1232.     strLine = cmCodeModule.Lines(lngProcFirstLine, 1)
  1233.     ' Now check whether this is a subroutine a function or a property procedure
  1234.     If InStr(1, strLine, "Sub") Then
  1235.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1236.         strFunctionType = "Sub"
  1237.     ElseIf InStr(1, strLine, "Function") Then
  1238.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Proc)
  1239.         strFunctionType = "Function"
  1240.     ElseIf InStr(1, strLine, "Property Get") Then
  1241.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Get)
  1242.         strFunctionType = "Property"
  1243.     ElseIf InStr(1, strLine, "Property Set") Then
  1244.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Set)
  1245.         strFunctionType = "Property"
  1246.     ElseIf InStr(1, strLine, "Property Let") Then
  1247.         lngProcFirstLine = cmCodeModule.ProcBodyLine(strProcName, vbext_pk_Let)
  1248.         strFunctionType = "Property"
  1249.     Else
  1250.         ' Generic error message
  1251.         MsgBox "Unrecognised routine type"
  1252.         Exit Sub
  1253.     End If
  1254.     ' Copy the line number for the start of the procedure to a variable to hold
  1255.     ' the current line of the procedure
  1256.     lngCurrentLine = lngProcFirstLine + 1
  1257.     ' And get the first line
  1258.     strLine = cmCodeModule.Lines(lngCurrentLine, 1)
  1259.     booInsertError = False
  1260.     Do Until booInsertError = True
  1261.         For I = 1 To Len(strLine)
  1262.             If Len(strLine) = 0 Then
  1263.                 Exit For
  1264.             End If
  1265.             strCurrentCharacter = Mid$(strLine, I, 1)
  1266.             If strCurrentCharacter = "'" Then
  1267.                 ' Check that we haven't got to the 'Place Code Here Prompt
  1268.                 If Trim$(strLine) = "' PLACE CODE HERE !!!!!" Then
  1269.                     booInsertError = True
  1270.                     lngCurrentLine = lngCurrentLine - 1
  1271.                     Exit For
  1272.                 End If
  1273.                 Exit For
  1274.             ElseIf strCurrentCharacter <> " " Then
  1275.                 ' The next character isn't a comment or a space so we need to insert
  1276.                 ' the error handler here
  1277.                 booInsertError = True
  1278.                 lngCurrentLine = lngCurrentLine - 1
  1279.                 Exit For
  1280.             End If
  1281.         Next I
  1282.         ' Get the next line to check
  1283.         lngCurrentLine = lngCurrentLine + 1
  1284.         strLine = cmCodeModule.Lines(lngCurrentLine, 1)
  1285.     Loop
  1286.     ' Insert the On Error Goto statement
  1287.     strProc = vbCrLf & "' Error Handler" & vbCrLf & "On Error Goto " & strProcName & "_Error" & vbCrLf
  1288.     cmCodeModule.InsertLines lngCurrentLine, strProc
  1289.     lngCurrentLine = lngCurrentLine + 4
  1290.     ' Now we need to move to the end of the procedure
  1291.     ' Create the end of the generic error handler
  1292.     If VBC.Type = vbext_ct_ClassModule Then
  1293.         strProc = vbCrLf & "Exit " & strFunctionType & vbCrLf & vbCrLf & "' Error Routine " _
  1294.         & vbCrLf & strProcName & "_Error:" & vbCrLf _
  1295.         & "Err.Raise Err.Number, " & """" & strProcName & """" & ", Err.Description" _
  1296.         & vbCrLf
  1297.     Else
  1298.         strProc = vbCrLf & "Exit " & strFunctionType & vbCrLf & vbCrLf & "' Error Routine " _
  1299.         & vbCrLf & strProcName & "_Error:" & vbCrLf & "msgbox ""Error # "" & Err.Number & "": "" & Err.Description & "" In " & strProcName & """" & vbCrLf
  1300.     End If
  1301.     ' First check whether we are already at the end of the procedure
  1302.     If Mid$(strLine, 1, 7) = "End Sub" Then
  1303.         cmCodeModule.InsertLines lngCurrentLine, strProc
  1304.     ElseIf Mid$(strLine, 1, 12) = "End Function" Then
  1305.         cmCodeModule.InsertLines lngCurrentLine, strProc
  1306.     ElseIf Mid$(strLine, 1, 12) = "End Property" Then
  1307.         cmCodeModule.InsertLines lngCurrentLine, strProc
  1308.     Else
  1309.         ' We will need to get to the end of the procedure
  1310.         Do
  1311.             strLine = cmCodeModule.Lines(lngCurrentLine, 1)
  1312.             If strFunctionType = "Sub" Then
  1313.                 If Mid$(strLine, 1, 7) = "End Sub" Then
  1314.                     cmCodeModule.InsertLines lngCurrentLine, strProc
  1315.                     Exit Do
  1316.                 End If
  1317.             ElseIf strFunctionType = "Function" Then
  1318.                 If Mid$(strLine, 1, 12) = "End Function" Then
  1319.                     cmCodeModule.InsertLines lngCurrentLine, strProc
  1320.                     Exit Do
  1321.                 End If
  1322.             ElseIf strFunctionType = "Property" Then
  1323.                 If Mid$(strLine, 1, 12) = "End Property" Then
  1324.                     cmCodeModule.InsertLines lngCurrentLine, strProc
  1325.                     Exit Do
  1326.                 End If
  1327.             End If
  1328.             lngCurrentLine = lngCurrentLine + 1
  1329.         Loop
  1330.     End If
  1331. Exit Sub
  1332. ' Error Routine
  1333. CreateErrorHandlerOnly_Error:
  1334. If Err.Number = 35 Then
  1335.     ' Check for error 35 so we can recognise property functions in classes
  1336.     Resume Next
  1337.     MsgBox "Error # " & Err.Number & ": " & Err.Description & " In CreateErrorHandlerOnly"
  1338. End If
  1339. End Sub
  1340.